package com.example.sqlite.initilizer;

import com.example.sqlite.meta.service.ExecService;
import com.example.sqlite.user.dao.entity.UserEntity;
import com.example.sqlite.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class SqliteDemoRunner implements CommandLineRunner {

    @Autowired
    private UserService userService;
    @Autowired
    private ExecService execService;

    @Override
    public void run(String... args) throws Exception {
        execService.dropTableIfExests("user");
        execService.execSQL("CREATE TABLE user (\n" +
                "  id BIGINT(20) NOT NULL,\n" +
                "  name VARCHAR(30) NULL DEFAULT NULL,\n" +
                "  age INT(11) NULL DEFAULT NULL,\n" +
                "  email VARCHAR(50) NULL DEFAULT NULL,\n" +
                "  PRIMARY KEY (id)\n" +
                ")");
        execService.execSQL("INSERT INTO user (id, name, age, email) VALUES\n" +
                "  (1, 'Jone', 18, 'test1@baomidou.com'),\n" +
                "  (2, 'Jack', 20, 'test2@baomidou.com'),\n" +
                "  (3, 'Tom', 28, 'test3@baomidou.com'),\n" +
                "  (4, 'Sandy', 21, 'test4@baomidou.com'),\n" +
                "  (5, 'Billie', 24, 'test5@baomidou.com')");
        System.out.println(userService.getUserEntity(2));
        UserEntity userEntity = new UserEntity();
        userEntity.setName("Tom");
        System.out.println(userService.getUserEntityList(userEntity));
        System.out.println(userService.getUserEntityPageList());
    }
}
